<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2024/3/7
  Time: 16:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<html>
<head>
    <title>品牌馆</title>
    <link rel="stylesheet" href="css/brand.css">
    <script type="text/javascript" src="js/jquery.min.js"></script>
</head>
<body>
<%@include file="header.jsp" %>
<section>
    <div id="section-top">
        <ul>
            <li id="brands">
            </li>
        </ul>
    </div>
</section>
<%@include file="footer.jsp" %>
</body>
<script>
    window.onload = function () {
        getStoreCommodity();
    }

    let brand = '';
    const brands = $("#brands");
    function getStoreCommodity() {
        $.ajax({
            type: "post",
            url: "store/getStoreCommodity",
            success: function (res) {
                if (res.msg == "success") {
                    const store = res.data;
                    console.log(store)
                    for (let j = 0; j < store.length; j++) {
                        brand =
                            "<ul class=\"brand-commodity\"><li class=\"brand-store\">" +
                            "<img src='../" + store[j].storeImg + "'><p><a href='store.jsp?storeId=" + store[j].storeId + "'>" + store[j].storeName + "</a></p></li>" +
                            "<div class=\"div_recommend\"><ul class=\"ul_recommend\">";
                        for (let i = 0; i < store[j].commodityList.length; i++) {
                            brand +=
                                "<a href='/patMall/commodityDetails.jsp?commodityId=" + store[j].commodityList[i].commodityId + "'>" +
                                "<li class='li_recommend' title='" + store[j].commodityList[i].commodityName + "'>" +
                                "<img src='../" + store[j].commodityList[i].commodityImgList[0].commodityImg + "' class='li_img'>" +
                                "<p class='li_p'>" + store[j].commodityList[i].commodityName + "</p>" +
                                "<p class='money'>￥" + store[j].commodityList[i].commodityPrice + "</p></li></a>";
                        }
                        brand += "</ul></div></ul>";
                        brands.append(brand);
                    }
                } else if (res.msg == "fail") {
                    alert("商品查询失败");
                } else if (res.msg == "NoFound") {
                    alert("没有商品");
                }
            },
            error: function () {
                alert("Error");
            }
        })
    }
</script>
</html>
